#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<assert.h>

char* my_strncpy(char* str1, const char* str2, size_t num)
{
	int i = 0;
	char* cp = str1;

	assert(str1 && str2);

	for (i = 0; i < num; i++)
	{
		if (*str2 != '\0')
		{
			*str1 = *str2;
		}
		else
		{
			*str1 = 0;
		}
		str1++;
		str2++;
	}
	return cp;
}

int main()
{
	char arr1[20] = "xxxxxxxxxxxxxxx";
	char arr2[] = "abcdefg";

	printf("%s", strncpy(arr1, arr2, 3));
	printf("%s", my_strncpy(arr1, arr2, 3));
	return 0;
}